#include <iostream>
#include <algorithm>
#include <vector> 
#include <string>
using namespace std;
#define int long long


int n, m;
const int N = 100005;
vector<int> e[N];
int mi[N], mx[N];
int dp[N], st[N][20], lg[N];
int cntz, z[N], idz[N];
int X[N], Y[N];
int cntt;
int rt[N], ans[N];

struct node {
	int lc, rc, maxn, id;
}tr[N * 80];

void up(int p) {
	int lc = tr[p].lc, rc = tr[p].rc;
	if (tr[lc].maxn >= tr[rc].maxn)tr[p].maxn = tr[lc].maxn, tr[p].id = tr[lc].id;
	else tr[p].maxn = tr[rc].maxn, tr[p].id = tr[rc].id;
}

void ins(int& p, int l, int r, int index, int jv) {
	if (!p)p = ++cntt;
	if (l == r) {
		tr[p].maxn += jv;
		tr[p].id = l;
		return;
	}
	int m = (l + r) >> 1;
	if (index <= m)ins(tr[p].lc, l, m, index, jv);
	else ins(tr[p].rc, m + 1, r, index, jv);
	up(p);
}

int merge(int p, int q, int l, int r) {
	if (!p)return q; if (!q)return p;
	if (l == r) {
		tr[p].maxn += tr[q].maxn;
		return p;
	}
	int m = (l + r) >> 1;
	tr[p].lc = merge(tr[p].lc, tr[q].lc, l, m);
	tr[p].rc = merge(tr[p].rc, tr[q].rc, m + 1, r);
	up(p);
	return p;
}

void fi(int u, int fa) {
	for (int v : e[u]) {
		if (v != fa) {
			fi(v, u);
			rt[u] = merge(rt[u], rt[v], 1, cntz);
		}
	}
	ans[u] = tr[rt[u]].maxn == 0 ? 0 : tr[rt[u]].id;
}

void dfs(int u, int fa) {
	dp[u] = dp[fa] + 1; st[u][0] = fa;

	for (int i = 1; i <= lg[dp[u]]; i++) {
		st[u][i] = st[st[u][i - 1]][i - 1];
	}
	for (int v : e[u]) {
		if (v != fa)
			dfs(v, u);
	}
}

int LCA(int x, int y) {
	if (dp[x] < dp[y])swap(x, y);

	while (dp[x] > dp[y]) {
		x = st[x][lg[dp[x] - dp[y]]];
	}
	if (x == y) {
		return x;
	}

	for (int i = lg[dp[x]]; i >= 0; i--) {
		if (st[x][i] != st[y][i]) {
			x = st[x][i];
			y = st[y][i];
		}
	}

	return st[y][0];
}


void solve() {
	cin >> n >> m;
	for (int i = 2; i <= n; i++)lg[i] = lg[i >> 1] + 1;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (int i = 1; i <= m; i++) {
		cin >> X[i] >> Y[i] >> z[i];
		idz[i] = z[i];
	}
	dfs(1, 0);
	sort(idz + 1, idz + 1 + m);
	cntz = unique(idz + 1, idz + 1 + m) - idz - 1;
	for (int i = 1; i <= m; i++) {
		int p = LCA(X[i], Y[i]);
		int zt = lower_bound(idz + 1, idz + 1 + cntz, z[i]) - idz;
		ins(rt[X[i]], 1, cntz, zt, 1);
		ins(rt[Y[i]], 1, cntz, zt, 1);
		ins(rt[p], 1, cntz, zt, -1);
		ins(rt[st[p][0]], 1, cntz, zt, -1);
	}
	fi(1, 0);
	for (int i = 1; i <= n; i++)cout << idz[ans[i]] << '\n';
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
